package com.cssw.fyzb.core.dao.exchange;

import com.cssw.fyzb.core.model.dodb.Appeal;
import com.cssw.fyzb.core.model.dodb.YExchangeFDef;
import com.ydn.dbframe.plugin.activerecord.Page;
import com.ydn.dbframe.plugin.activerecord.parse.SqlParse;
import org.springframework.stereotype.Repository;

import java.math.BigDecimal;
import java.util.Date;
import java.util.Map;

/**
 * asa
 * 2020/12/21
 */
@Repository
public class YExchangeFDefDaoImpl implements  YExchangeFDefDao {
    public YExchangeFDef getYExchangeFDef(Long yf_id) {
        return YExchangeFDef.dao.findById(yf_id);
    }

    @Override
    public Page<YExchangeFDef> getAllDef(Map param, int page, int limit) {
        SqlParse sqlParse = new SqlParse(param);
        sqlParse.addSQL("SELECT * from t_y_exchange_f_def ");
        sqlParse.addSQL(" WHERE state='1'");
        return YExchangeFDef.dao.paginate(page, limit, sqlParse);
    }

    @Override
    public  void delete(Long yfId,Long userId){
        YExchangeFDef yExchangeFDef = new YExchangeFDef();
        yExchangeFDef.setYfId(yfId);
        yExchangeFDef.setUpdateOperId(userId);
        yExchangeFDef.setUpdateTime(new Date());
        yExchangeFDef.setState("0");
        yExchangeFDef.update();
    }

    @Override
   public void update(Long yfId, BigDecimal yCoin, BigDecimal fCoin, Long userId){
       YExchangeFDef yExchangeFDef = new YExchangeFDef();
       yExchangeFDef.setYfId(yfId);
       yExchangeFDef.setUpdateOperId(userId);
       yExchangeFDef.setUpdateTime(new Date());
       yExchangeFDef.setFCoin(fCoin);
       yExchangeFDef.setYCoin(yCoin);
       yExchangeFDef.update();
    }

    @Override
    public void  add( BigDecimal yCoin, BigDecimal fCoin, Long userId){
        YExchangeFDef yExchangeFDef = new YExchangeFDef();
        yExchangeFDef.setCreateOperId(userId);
        yExchangeFDef.setCreateTime(new Date());
        yExchangeFDef.setFCoin(fCoin);
        yExchangeFDef.setYCoin(yCoin);
        yExchangeFDef.setState("1");
        yExchangeFDef.save();
    }
}